package com.qzf.test.test;

import com.qzf.test.model.Brand;
import com.qzf.test.model.Cell;
import com.qzf.test.model.Layer;
import com.qzf.test.utils.LayerUtils;
import javax.swing.*;

public class TestReaderLayer extends JFrame {

    public static void main(String[] args) {
        new TestReaderLayer();
    }
    private Layer layer = LayerUtils.builderLayer(6,6);
    public TestReaderLayer(){
        this.setTitle("羊了羊");
        this.setSize(450,800);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //清除系统默认布局
        this.setLayout(null);
        //居中显示
        this.setLocationRelativeTo(null);
        this.setVisible(true);

        //设置位置
        this.setBounds(0,0,450,800);
        //获取格子数目
        Cell[][] cells = layer.getCells();
        for (int i=0;i<cells.length;i++){
            for (int j=0;j<cells[i].length;j++){
                Brand brand = cells[i][j].getBrand();
                int x = j*50;
                int y = i*50;
                brand.setBounds(x,y,50,50);
                //将卡牌一张一张绘制到窗口中
                this.getContentPane().add(brand);
            }
        }

        new  Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    repaint();
                    try {
                        Thread.sleep(40);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }



            }
        }).start();


    }
}
